package com.tasly.attendance.domain.calc.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.tasly.attendance.domain.calc.Calculator;

/**
 * Use this calculator to anaylse the nightly working hours
 * 19:00 - unconfirmed time, the working date time will be end
 * at next day, so can not found the end time in one day pool.
 * 
 * if the pool size for some day is 1, and the only time is after 19:00
 * we think the person do some job nightly.
 * 
 * @author Sam Li
 *
 */
public class NightlyWorkingHoursCalculatorImpl implements Calculator {
    
    private static final double NIGHTLY_WORKING_HOURS = 12;

    @Override
    public double calculate(List<Date> dateCalculatePoolList,Date dateLimit) {
        
        Calendar calendar = Calendar.getInstance();
//        Date standardStartDatetime = null;
        Date standardEndDateTime = null;
        //8 hours check
        calendar.setTime(dateLimit);
        //set latest limit time to 19:00
        calendar.set(Calendar.HOUR_OF_DAY, 19);
        standardEndDateTime = calendar.getTime();
        //set start limit time to 18:00
//        calendar.set(Calendar.HOUR_OF_DAY, 18);
//        standardEndDateTime = calendar.getTime();
        //get first swing card time in the day
        Date firstSwingCardDateTime = dateCalculatePoolList.get(0);
        //get latest swing card time in the day
        Date latestSwingCardDateTime = dateCalculatePoolList.get(dateCalculatePoolList.size()-1);
        if (firstSwingCardDateTime.after(standardEndDateTime) && latestSwingCardDateTime.after(standardEndDateTime)) {
            return NIGHTLY_WORKING_HOURS;
        } else {
            return INVALID_HOURS;
        }
    }

}
